// library imports
#include <iostream>

// function declaration
int moveRobots(int *, int *, int, int );
int getNew(int, int);

// main function
int main()
{
	//	Return values : None
	//	Description of args : No arguments passed
	//	How they are passed : No arguments passed
	//	Description : This is the main function. Which takes moves from the user. 
	//					Update the user moves and conculate if the robot caught the user and update the status.


	// basic initialization
	int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1;

  	// initialize positions of four robots
  	x[0] = 0; y[0] = 0;
  	x[1] = 0; y[1] = 50;
  	x[2] = 50; y[2] = 0;
  	x[3] = 50; y[3] = 50;

  	std::cout << "Your coordinates: 25 25\n";

	// take inputs
  	while (status == 1) {
    	std::cout << "Enter move (1 for +x, -1 for -x, 2 for + y, -2 for -y):";
    	std::cin >> move;

    // process user's move
    if (move == 1)
      	myX++;
    else if (move == -1)
      	myX--;
    else if (move == 2)
      	myY++;
    else if (move == -2)
      	myY--;

    // update robot positions
    status = moveRobots(&x[0],&y[0],myX,myY);

	// print user coordinates
    std::cout << "Your coordinates: " << myX << " " << myY <<std:: endl;

	// print robot coordinates
    for (i=0;i<4;i++)
        std::cout << "Robot at " << x[i] << " " << y[i] << std::endl;

  	}
    std::cout << "AAAARRRRGHHHHH... Game over\n";
}

// Moves robots 
int moveRobots(int *arg0, int *arg1, int arg2, int arg3)
{
	//	Return values : alive(int)
	//	Description of args : *arg0 = update x-coordinate of robot i, *arg1 = update y-coordinate of robot i, 
	//							arg2 = x-coordinate given by user, arg3 = y-coordinate given by user 
	//	How they are passed : They are passed in integer format
	//	Description : This function moves robot. It takes arg0 & arg1 as argument which are old values of coorfinates.
	//   				arg2 & arg3 are used to move user.   
						
	// basic initialization
	int i, *ptrX, *ptrY, alive = 1;

  	ptrX = arg0;
  	ptrY = arg1;

	// updates the coordinates of robot
  	for (i=0;i<4;i++) {
    	*ptrX = getNew(*ptrX,arg2);  // update x-coordinate of robot i
    	*ptrY = getNew(*ptrY,arg3);  // update y-coordinate of robot i

    	// check if robot caught user
    	if ((*ptrX == arg2) && (*ptrY == arg3)) {
      		alive = 0;
      		break;
    	}
    	ptrX++;
    	ptrY++;
  	}
  	
  	// return alive status
  	return alive;
}

// move coordinate of robot closer to coordinate of user
int getNew(int arg0, int arg1)
{
	//	Return values : result(int)
	//	Description of args : arg0 = update x-coordinate of robot i, arg1 = update y-coordinate of robot i
	//	How they are passed : They are passed in integer format
	//	Description : This function moves robot closer to the user. It takes arg0 & arg1 as arguments, 
	//					then calculating difference between arg0 and arg1.
	//					After that, they are compared and value of result are increased or decreased by 1.
	
	// variable declaration
  	int temp, result;

	// update the value of result
  	temp = arg0 - arg1;
  	if (temp >= 10)
    	result = arg0 - 10;
  	else if (temp > 0)
    	result = arg0 - 1;
  	else if (temp == 0)
    	result = arg0;
  	else if (temp > -10)
    	result = arg0 + 1;
  	else if (temp <= -10)
    	result = arg0 + 10;

  	return result;
}